package com.soft.controller;

import com.soft.pojo.Dept;
import com.soft.service.DeptService;
import com.soft.utils.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ruoxi
 * @create 2021-12-28 11:41
 */
@WebServlet("/editDeptByDno")
public class EditDeptByDnoServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        int dno = Integer.parseInt(req.getParameter("dno"));
        String dName = req.getParameter("dName");
        String tel = req.getParameter("tel");
        String dPlace = req.getParameter("dPlace");

        Dept dept = new Dept();
        dept.setDno(dno);
        dept.setdName(dName);
        dept.setTel(tel);
        dept.setdPlace(dPlace);

        DeptService deptService = new DeptService();
        Result result = deptService.editDeptByDno(dept);

        req.setAttribute("editDeptMsg", result.getMsg());
        req.getRequestDispatcher("showAllDeptByPage").forward(req,resp);
    }
}
